<?php
/**
*	本地转pdf
*/
namespace Rainrock\Framework\Chajian;


use Rainrock\Framework\kernel\core\Chajian;
use Rainrock\Framework\kernel\base\Base;
use Rainrock\Framework\kernel\base\Jiami;



class localcmdChajian extends Chajian{

	//UDP服务器主机，不需要修改
	private $serverhost = '127.0.0.1';
	
	//UDP服务端口，数字类型
	private $serverport = 780;			
	
	/**
	*	UDP发送文本
	*/
	public function udpsend($str, $port=0)
	{
		if(!function_exists('socket_create'))return '没有开启Socket组件';
		$sock 	= socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
		$len 	= strlen($str);
		if($port==0)$port = $this->serverport;
		$bo 	= socket_sendto($sock, $str, $len, 0, $this->serverhost, $port);
		socket_close($sock);
		return $bo;
	}
	
	/**
	*	转pdf发送命令
	*	path 完整路径
	*/
	public function topdf($path, $type, $id)
	{
		$flx	= 'doc';
		if($type=='xls' || $type=='xlsx')$flx='xls';
		if($type=='ppt' || $type=='pptx')$flx='ppt';
		$topah 	= ''.ROOT_PACK.'/topdf/'.$flx.'.js';
		$url  	= ''.URLLOCAL.'?m=filepdf&a=topdfback&id='.$id.'';
		$path 	= ''.ROOT_PACK.'/topdf/start.bat "'.$topah.'" "'.$path.'" "'.$url.'"';
		$bo 	= $this->udpsend($path);
		return $bo;
	}
	
	/**
	*	转pdf发送命令
	*/
	public function topdfxls($path, $type, $id)
	{
		$outdir	= substr($path,0, strripos($path,'/'));
		$path 	= ''.ROOT_PACK.'/topdf/startxls.bat "'.ROOT_PACK.'/'.$path.'" "'.ROOT_PACK.'/'.$outdir.'" '.$id.'';
		$bo 	= $this->udpsend($path);
		return $bo;
	}
}